package com.scoressystem.controller;
import com.scoressystem.pojo.ScoreBean;
import com.scoressystem.pojo.Student;
import com.scoressystem.service.ScoreService;
import com.scoressystem.service.StudentService;
import com.scoressystem.utils.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("Status")
public class StatusController {
    @Autowired
    StudentService studentService;
    @Autowired
    ScoreService scoreService;
    @RequestMapping("teacher")
    public Results teacher() {
        Map<String , Object> map = new HashMap<String , Object>();
        List<String> names = new ArrayList<String>();
        List<Double> scores=new ArrayList<>();
        List<Student> students=studentService.selectAllStudentBydel();
        for(Student student:students){
            names.add(student.getStuName());
            scores.add(scoreService.selectSumScore(String.valueOf(student.getStuNo())));
        }
        map.put("names", names);
        map.put("scores", scores);
        return  new Results("0","查询数据成功",map);
    }
    @RequestMapping("student")
    public Results student(HttpSession session) {
        String studentNo= String.valueOf(session.getAttribute("stuNo"));
        List<Object[]> list=new ArrayList<>();
        List<ScoreBean> scoreBeans=studentService.selectAllScorebean(studentNo);
        for(ScoreBean scoreBean:scoreBeans){
            String name=scoreBean.getName();
            Double score=scoreBean.getScore();
            Object[] params=new Object[]{name,score};
            list.add(params);
        }
        return new Results("0","查询成功",list);
    }
}
